
interface LanguagePageData{
  currentLanguage:string,
  languagePack:object
}

interface LanguagePageMethods{
  changeLanguage(language:string):void
}

Page<LanguagePageData,LanguagePageMethods>({
  data: {
    currentLanguage: 'zh-Hans',
    languagePack:{}
  },
  onLoad() {
    //TODO:读取当前保存的语言
    this.setData({currentLanguage:'zh-Hans'});
  },
  onReady() {
    // 页面加载完成
    my.requestSubscribeMessage
  },
  onShow() {
    // 页面显示时重新加载语言
    var resources:object = require("/locale/"+this.data.currentLanguage+"/translate.json");
    this.setData({languagePack :resources});

  },
  changeLanguage(language:string){
    //TODO:改变语言
    if (language=='system')
    {
      if (my.canIUse('env')) {
        if (my.env.language=='en'){
          this.setData({currentLanguage:my.env.language});
          var resources:object = require("/locale/"+this.data.currentLanguage+"/translate.json");
          this.setData({languagePack :resources});
          return;
        }
      }
    }    
    this.setData({currentLanguage:language});
    var resources:object = require("/locale/"+this.data.currentLanguage+"/translate.json");
    if (this.data.currentLanguage=='en'){
      this.setData({languagePack :resources});
    } else {
      this.setData({languagePack :resources});
    }
  }
});
